package com.example.common.constants;

/**
 * 服务名称常量
 * 
 * @author: Allen
 * @create: 2025/7/3 16:38
 * @description: 定义系统中所有服务的名称
 **/
public enum ServiceNames {
    
    GATE("gate-service", 1000, 1999),
    LOBBY("lobby-service", 2000, 2999),
    GAME("game-service", 3000, 3999);
    
    private final String value;
    private final int startId;
    private final int endId;
    
    ServiceNames(String value, int startId, int endId) {
        this.value = value;
        this.startId = startId;
        this.endId = endId;
    }
    
    public String value() {
        return value;
    }
    
    public int getStartId() {
        return startId;
    }
    
    public int getEndId() {
        return endId;
    }
    
    /**
     * 检查服务器ID是否属于该服务类型
     * 
     * @param serverId 服务器ID
     * @return 是否属于该服务类型
     */
    public boolean isServerIdInRange(int serverId) {
        return serverId >= startId && serverId <= endId;
    }
    
    /**
     * 根据服务器ID获取服务类型
     * 
     * @param serverId 服务器ID
     * @return 服务类型，如果不在任何范围内返回null
     */
    public static ServiceNames getServiceByServerId(int serverId) {
        for (ServiceNames service : values()) {
            if (service.isServerIdInRange(serverId)) {
                return service;
            }
        }
        return null;
    }
    
    /**
     * 验证服务器ID是否有效
     * 
     * @param serverId 服务器ID
     * @return 是否有效
     */
    public static boolean isValidServerId(int serverId) {
        return getServiceByServerId(serverId) != null;
    }
} 